package com.wl156.adapters;

import org.ksoap2.serialization.SoapObject;

import com.wl156.lite.R;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PlaceAdapter extends CheckableAdapter implements OnClickListener {

	public PlaceAdapter(Context context, SoapObject data) {
		mInflater = LayoutInflater.from(context);
		mData = data;
		mContext = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_find_place, null);
		}

		TextView name = (TextView) convertView.findViewById(R.id.name);
		TextView type = (TextView) convertView.findViewById(R.id.type);
		TextView business = (TextView) convertView.findViewById(R.id.business);

		TextView longitude = (TextView) convertView
				.findViewById(R.id.longitude);
		TextView latitude = (TextView) convertView.findViewById(R.id.latitude);
		TextView radius = (TextView) convertView.findViewById(R.id.radius);

		TextView phoneDial = (TextView) convertView.findViewById(R.id.dial);
		phoneDial.setOnClickListener(this);

		setTextViewStringFromProperty(position, name, 1);
		setTextViewStringFromProperty(position, type, 2);
		setTextViewStringFromProperty(position, business, 3);
		setTextViewStringFromProperty(position, longitude, 5);
		setTextViewStringFromProperty(position, latitude, 6);
		setTextViewStringFromProperty(position, radius, 7);

		setPhoneView(position, phoneDial, 4);
		super.getView(position, convertView, parent);
		return convertView;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dial:
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.parse("tel:" + v.getTag().toString()));
			mContext.startActivity(i);
			break;
		}
	}
}
